//
//  topicCell.m
//  百思不得解国内
//
//  Created by LeeBruce on 16/8/5.
//  Copyright © 2016年 sunnyday. All rights reserved.
//

#import "topicCell.h"
#import "topicM.h"
#import <UIImageView+WebCache.h>
@interface topicCell()
@property (weak, nonatomic) IBOutlet UIImageView *profileImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *createTimeLabel;
@property (weak, nonatomic) IBOutlet UIButton *dingButton;
@property (weak, nonatomic) IBOutlet UIButton *caiButton;
@property (weak, nonatomic) IBOutlet UIButton *shareButton;
@property (weak, nonatomic) IBOutlet UIButton *commentButton;

@end
@implementation topicCell

- (void)awakeFromNib
{
    UIImageView *bgView = [[UIImageView alloc] init];
    bgView.image = [UIImage imageNamed:@"mainCellBackground"];
    self.backgroundView = bgView;
}


- (void)setTopic:(topicM *)topic
{
    _topic = topic ;
    
    // 设置头像
    [self.profileImageView sd_setImageWithURL:[NSURL URLWithString:topic.profile_image] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"]];
    // set name
    self.nameLabel.text = topic.name;
    
    // create topic time
    self.createTimeLabel.text = topic.create_time;
    
    // set button text
    [self setupButtonTitle:self.dingButton count:topic.ding placeholder:@"顶"];
    [self setupButtonTitle:self.caiButton count:topic.cai placeholder:@"踩"];
    [self setupButtonTitle:self.shareButton count:topic.repost placeholder:@"分享"];
    [self setupButtonTitle:self.commentButton count:topic.comment placeholder:@"评论"];
    
    
}

/**
 * 设置底部按钮文字
 */

- (void)setupButtonTitle:(UIButton *)button count:(NSInteger)count placeholder:(NSString *)placeholder
{
    if (count > 10000) {
        placeholder = [NSString stringWithFormat:@"%.1f 万", count / 10000.0];
    }else if (count > 0){
        placeholder = [NSString stringWithFormat:@"%zd" , count];
    }
    [button setTitle:placeholder forState:UIControlStateNormal];
}
@end
